#include "mainwindow.h"
#include "jsoncpppath.h"

#include <iostream>
#include <QApplication>
#include <QtDebug>


#ifdef QT_DEBUG
#define ai_fresh_goods_dll "debug/fresh-goods-distinguish-windows.dll"
#else
#define ai_fresh_goods_dll "release/fresh-goods-distinguish-windows.dll"
#endif

#ifdef USE_MSVC
#include <msclr/marshal.h>
#using ai_fresh_goods_dll
#using <System.Drawing.dll>
#endif


namespace ai_fresh_goods{
#ifdef USE_MSVC

using namespace System;
using namespace System::Text;
using namespace System::Drawing;

using namespace msclr::interop;
using namespace fresh_goods_distinguish_windows;
using namespace std;

/*
 * object AIConst {
    //公司标识，需要电话联系进行申请 companyID、appKey、secretKey、serviceKey，用以激活sdk
    val companyID = "D84ScnlmvbpNmTwk/A3YGQ=="
    val APP_KEY = "21102f404a4e48978234ede46ae55c14"
    val SECRET_KEY = "10490abf7d874f42a23c3641d576982b"
    val SERVICE_KEY = "4c495ca26fb2efb21e3b90edf299e7ed"

    val AI_DEFAULT_CODE = 8888

    var rootPath = "" //Environment.getExternalStorageDirectory().toString() + "/AiScale"

    var ACTIVATE_FLAG = false//是否要激活状态位

    var ACTIVATE_CODE = ""//激活码  测试码 151311350383;041850937075

    var STORE_ID : Long = 0//
    var STORE_NAME = ""//

}
*/
void init() {
    FreshGoodsManager mManager;
    // const char * rootPath = "\\AiModule";
    // string sessionId = "";
    // const char * mCompanyID = "你的公司ID"; //在平台注册完事后联系创建人员 生成公司ID
    // // 普通鉴权
    // auto mAppKey = "你的appKey";
    // auto mSecretKey = "你的secretKey";
    // auto mServiceKey = "你的serviceKey";
    // auto storeId = "9999";
    // auto storeName = "测试店铺";
    const char * companyID = "D84ScnlmvbpNmTwk/A3YGQ==";
    QString APP_KEY = "21102f404a4e48978234ede46ae55c14";
    QString SECRET_KEY = "10490abf7d874f42a23c3641d576982b";
    QString SERVICE_KEY = "4c495ca26fb2efb21e3b90edf299e7ed";

    auto AI_DEFAULT_CODE = 8888;

    QByteArray rootPath = "D:/AiModule";//qApp->applicationDirPath().toLocal8Bit();

    auto ACTIVATE_FLAG = false;//是否要激活状态位

    auto ACTIVATE_CODE = "";//激活码  测试码 151311350383;041850937075

    auto STORE_ID = 0;//
    auto STORE_NAME = "";//

    auto initKeyInfo = JsonCppVoid()
                       .append("/appKey", APP_KEY)
                       .append("/secretKey", SECRET_KEY)
                       .append("/serviceKey", SERVICE_KEY)
                       .toJson();
        ;

    qDebug() << "companyID:" << companyID << "\n"
             << "initKeyInfo:" << initKeyInfo << "\n"
             << "rootPath:" << rootPath << "\n"
        ;

        qDebug() << "RetailBot_Api_ModelInit" ;
    marshal_context context;
    String ^p_mCompanyID = context.marshal_as<String ^>(companyID);
    String ^p_mInitKeyInfo = context.marshal_as<String ^>(initKeyInfo.data());
    String ^p_rootPath = context.marshal_as<String ^>(rootPath.data());

    //初始化
    int init = mManager.RetailBot_Api_ModelInit(p_mCompanyID, p_mInitKeyInfo, p_rootPath, 1);
    qDebug() << init;

    //学习
    StringBuilder ^sid = gcnew StringBuilder();
    StringBuilder ^result = gcnew StringBuilder();
    Bitmap^ bitmap = gcnew Bitmap("C:/Users/cz/Desktop/banana.png");

//    Bitmap bitmapRecognition = "";//之前拍摄的bitmap数据
//    int code = mManager.RetailBot_Api_Recognition(sid, result, bitmapRecognition);
//    string sessionId = sid.ToString();
//    string bufferData = result.ToString();

}
#else
void init(){
    qDebug() << "fresh-goods-distinguish-windows.dll only run in msvc environment.";
}
#endif
}//~namespace ai_fresh_goods

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    ai_fresh_goods::init();


    MainWindow w;
    w.show();

    return a.exec();
}
